package com.zhangliuliu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhangliuliu.bean.RatsBean;
import com.zhangliuliu.service.RatService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("rat")
public class ratController {

    @Resource
    private RatService ratService;
    @RequestMapping("cut")
    @ResponseBody
    IPage<RatsBean> cut(@RequestParam(value = "pageNo",defaultValue = "1") int pageNo,
                        @RequestParam(value = "pageSize",defaultValue = "4") int pageSize,
                        @RequestParam("name") String name,
                        @RequestParam("food") String food,
                        @RequestParam("harm") String harm){
        return ratService.cut(pageNo,pageSize,name,food,harm);
    }

    @RequestMapping("add")
    @ResponseBody
    void addRat(RatsBean ratsBean){
        ratService.addRat(ratsBean);
    }

    @RequestMapping("select")
    @ResponseBody
    RatsBean select(int id){
        return ratService.select(id);
    }

    @RequestMapping("cutByItem")
    @ResponseBody
    IPage<RatsBean> cutByName(@RequestParam(value = "pageNo",defaultValue = "1") int pageNo,
                              @RequestParam(value = "pageSize",defaultValue = "4") int pageSize,
                              @RequestParam("name") String name){
        return  ratService.cutByName(pageNo,pageSize,name);
    }
}
